﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WucCloud.Database;
using WucCloud.Entity;
using SqlSugar;

namespace WucCloud.Application
{
    /// <summary>
    /// 用户角色关联服务
    /// </summary>
    public class UserRoleService :BaseService<UserRoleEntity>,IDependency
    {
        /// <summary>
        /// 子类构造函数
        /// </summary>
        /// <param name="userRepository"></param>
        public UserRoleService(IBaseRepository<UserRoleEntity> userroleRepository, IUnitOfWork unitOfWork)
        {
            base._repository = userroleRepository;
            base._unitOfWork = unitOfWork;
        }

        /// <summary>
        /// 获取具有角色的用户列表
        /// </summary>
        /// <param name="roleId">角色Id</param>
        /// <returns></returns>
        public async Task<List<UserInfoEntity>> GetRoleUsers(string roleId)
        {
            return await _repository.Db.Queryable<UserRoleEntity, UserInfoEntity>((A, B) => new object[] { JoinType.Left, A.UserId == B.KeyId })
                .Where((A, B) => A.RoleId == roleId)
                .Select((A, B) => B).ToListAsync();
        }
    }
}
